from pynput import keyboard
 
def on_press(key):
    try:
        print(key.name)
        # print(f'{str(key.code)},typ1e:{type((key))}')
    except AttributeError:
        print(f'{key}')
 
def on_release(key):
    # print(f'{key} released')
    pass
    # if key == keyboard.Key.esc:
    #     # 停止监听
    #     return False
import threading

# 监听按键事件
ke = keyboard.Listener(on_press=on_press, on_release=on_release)
ke.start()

# threading.Thread(target=ke.start, args=()).start()
print("程序已开启！")
ke.join()
